<!doctype html public "-//W3C//DTD HTML 4.0 Frameset//EN""http://www.w3.org/TR/REC-html40/frameset.dtd">
<html>
<head>
<title>
Zapatec Utils Overview
</title>
<link rel ="stylesheet" type="text/css" href="stylesheet.css" title="Style">
<script>
function asd() {
	
		parent.document.title="parse.js Overview";
	
}
</script>
</head>
<body bgcolor="white" onload="asd();">

<!-- ========== START OF NAVBAR ========== -->
<a name="navbar_top"><!-- --></a>
<table border="0" width="100%" cellpadding="1" cellspacing="0">
<tr>
<td colspan=2 bgcolor="#EEEEFF" class="NavBarCell1">
<a name="navbar_top_firstrow"><!-- --></a>
<table border="0" cellpadding="0" cellspacing="3">
  <tr align="center" valign="top">
  
  
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="overview-summary.html"><font class="NavBarFont1"><b>Overview</b></font></a>&nbsp;</td>
  <td bgcolor="#FFFFFF" class="NavBarCell1Rev">	&nbsp;<font class="NavBarFont1Rev"><b>File</b></font>&nbsp;</td>
  

  <td bgcolor="#FFFFFF" class="NavBarCell1"> 	<font class="NavBarFont1">Class</font>&nbsp;</td>
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="overview-tree.html"><font class="NavBarFont1"><b>Tree</b></font></a>&nbsp;</td>
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="index-all.html"--><font class="NavBarFont1"><b>Index</b></font></a>&nbsp;</td>
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="help-doc.html"><font class="NavBarFont1"><b>Help</b></font></a>&nbsp;</td>
  </tr>
</table>
</td>
<td bgcolor="#EEEEFF" align="right" valign="top">
<em>
<b>Zapatec Utils</b></em>
</td>
</tr>

<tr>
<td bgcolor="white" class="NavBarCell2"><font size="-2">
&nbsp;PREV&nbsp;
&nbsp;NEXT</font></td>
<td bgcolor="white" class="NavBarCell2"><font size="-2">
  <a href="index.html" target="_top"><b>FRAMES</b></a>  &nbsp;
&nbsp;<a href="overview-summary.html" target="_top"><b>NO FRAMES</b></a>
&nbsp;&nbsp;
<script>
  <!--
  if(window==top) {
    document.writeln('<A HREF="allclasses-noframe.html" TARGET=""><B>All Classes</B></A>');
  }
  //-->
</script>
<noscript>
<a href="allclasses-noframe.html" target=""><b>All Classes</b></a>
</noscript>
</font></td>
</tr>
</table>
<!-- =========== END OF NAVBAR =========== -->

<hr>
<center>
	
	   <h2>parse.js</h2>
	
</center>

	


<h4>Summary</h4>
<p>
	
		No overview generated for 'parse.js'<BR/><BR/>
	
</p>

<hr>



<!-- ========== METHOD SUMMARY =========== -->

<!-- ========== END METHOD SUMMARY =========== -->


        <pre class="sourceview"><span class="comment">// $Id: parse.js 15736 2009-02-06 15:29:25Z nikolai $</span>
<span class="comment">/*
 * &lt;pre&gt;
 * Copyright (c) 2004-2009 by Zapatec, Inc.
 * http://www.zapatec.com
 * 1700 MLK Way, Berkeley, California,
 * 94709, U.S.A.
 * All rights reserved.
 * &lt;/pre&gt;
 */</span>

Zapatec.Parse=<span class="reserved">function</span>(str2parse, delim)
{
<span class="reserved">this</span>.init()
<span class="reserved">this</span>.arr=[]
<span class="reserved">if</span> (arguments.length &gt; 1)
{
	<span class="reserved">this</span>.str2parse=<span class="reserved">this</span>.trim(str2parse)
	<span class="reserved">this</span>.delim=delim
	<span class="reserved">this</span>.parse(<span class="reserved">this</span>.str2parse, <span class="reserved">this</span>.delim)
}

}

Zapatec.Parse.<span class="reserved">prototype</span>.init=<span class="reserved">function</span>() {
}

Zapatec.Parse.<span class="reserved">prototype</span>.arr_clear=<span class="reserved">function</span>() {
	<span class="reserved">this</span>.arr=[]
}

Zapatec.Parse.<span class="reserved">prototype</span>.parse=<span class="reserved">function</span>(str2parse, delim) 
{
var i
<span class="reserved">this</span>.arr=str2parse.split(<span class="reserved">this</span>.delim)
<span class="reserved">for</span> (i=0; i&lt;<span class="reserved">this</span>.arr.length; i++)
	<span class="reserved">this</span>.arr[i]=<span class="reserved">this</span>.trim(<span class="reserved">this</span>.arr[i])
}

<span class="comment">// return number fields</span>
Zapatec.Parse.<span class="reserved">prototype</span>.NF=<span class="reserved">function</span>(s) { <span class="reserved">return</span> <span class="reserved">this</span>.arr.length }

<span class="comment">// check if field number is in range, 0 to N-1</span>
Zapatec.Parse.<span class="reserved">prototype</span>.validField=<span class="reserved">function</span>(iFld) { <span class="reserved">return</span> iFld &gt;=0 &amp;&amp; iFld &lt;=<span class="reserved">this</span>.NF()-1 }

<span class="comment">// get the field based on the field number</span>
Zapatec.Parse.<span class="reserved">prototype</span>.getField=<span class="reserved">function</span>(iFld) { 
<span class="reserved">if</span> (!<span class="reserved">this</span>.validField(iFld)) <span class="reserved">return</span> undefined
<span class="reserved">return</span> <span class="reserved">this</span>.arr[iFld]
}

<span class="comment">// set the field based on the field number, field number must be valid</span>
Zapatec.Parse.<span class="reserved">prototype</span>.setField=<span class="reserved">function</span>(iFld, value) { 
<span class="reserved">if</span> (!validField(iFld)) <span class="reserved">return</span> undefined
<span class="reserved">this</span>.arr[iFld]=value
}

<span class="comment">// push field to end of list</span>
Zapatec.Parse.<span class="reserved">prototype</span>.pushField=<span class="reserved">function</span>(value) { <span class="reserved">this</span>.arr.push(value) }

<span class="comment">// pop field off array</span>
Zapatec.Parse.<span class="reserved">prototype</span>.popField=<span class="reserved">function</span>(value) { <span class="reserved">return</span> <span class="reserved">this</span>.arr.pop() }

<span class="comment">// Add field into list a,b,d,e addField(2,0,c) --&gt; a,b,c,d,e</span>
Zapatec.Parse.<span class="reserved">prototype</span>.insertField=<span class="reserved">function</span>(iFld, value) { <span class="reserved">this</span>.arr.splice(iFld,0,value) }


<span class="comment">// trim Leading white spaces</span>
Zapatec.Parse.<span class="reserved">prototype</span>.pretrim = <span class="reserved">function</span>(s) {
  <span class="comment">// Convert to string</span>
  s += <span class="literal">''</span>;
  <span class="reserved">return</span> s.replace(/^\s?/, <span class="literal">''</span>);
};

<span class="comment">// trim Trailing white spaces</span>
Zapatec.Parse.<span class="reserved">prototype</span>.posttrim = <span class="reserved">function</span>(s) {
  <span class="comment">// Convert to string</span>
  s += <span class="literal">''</span>;
  <span class="reserved">return</span> s.replace(/\s?$/, <span class="literal">''</span>);
};

<span class="comment">// trim Leading and Trailing white spaces</span>
Zapatec.Parse.<span class="reserved">prototype</span>.trim=<span class="reserved">function</span>(s)
{
	s=<span class="reserved">this</span>.pretrim(s)
	s=<span class="reserved">this</span>.posttrim(s)
	<span class="reserved">return</span> s
}


<span class="comment">// For given array, flatfile with delim as separator</span>
Zapatec.Parse.<span class="reserved">prototype</span>.flatfile=<span class="reserved">function</span>(delimOut) 
{
var strFld, i, strFlat=<span class="literal">''</span>
<span class="reserved">for</span> (i=0; i&lt;<span class="reserved">this</span>.NF(); i++)
	{
	strFld=<span class="reserved">this</span>.getField(i) || <span class="literal">''</span>
	strFld=strFld.replace(/<span class="literal">"/, "</span>\<span class="literal">""</span>)
	<span class="reserved">if</span> (strFld.indexOf(delimOut) != -1) 
		<span class="comment">// if delim in field then enclose in quotes</span>
		strFld=<span class="literal">'"'</span> + strFld + <span class="literal">'"'</span>
	strFlat+=strFld
	<span class="reserved">if</span> (i&lt;<span class="reserved">this</span>.NF()-1)	
		<span class="comment">// last field?, no delim</span>
		strFlat += delimOut
	}

	<span class="reserved">return</span> strFlat
}
</pre>
	<hr>



<!-- ========== START OF NAVBAR ========== -->
<a name="navbar_top"><!-- --></a>
<table border="0" width="100%" cellpadding="1" cellspacing="0">
<tr>
<td colspan=2 bgcolor="#EEEEFF" class="NavBarCell1">
<a name="navbar_top_firstrow"><!-- --></a>
<table border="0" cellpadding="0" cellspacing="3">
  <tr align="center" valign="top">
  
  
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="overview-summary.html"><font class="NavBarFont1"><b>Overview</b></font></a>&nbsp;</td>
  <td bgcolor="#FFFFFF" class="NavBarCell1Rev">	&nbsp;<font class="NavBarFont1Rev"><b>File</b></font>&nbsp;</td>
  

  <td bgcolor="#FFFFFF" class="NavBarCell1"> <font class="NavBarFont1">Class</font>&nbsp;</td>
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="overview-tree.html"><font class="NavBarFont1"><b>Tree</b></font></a>&nbsp;</td>
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="index-all.html"--><font class="NavBarFont1"><b>Index</b></font></a>&nbsp;</td>
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="help-doc.html"><font class="NavBarFont1"><b>Help</b></font></a>&nbsp;</td>
  </tr>
</table>
</td>
<td bgcolor="#EEEEFF" align="right" valign="top"><em>
<b>Zapatec Utils</b></em>
</td>
</tr>

<tr>
<td bgcolor="white" class="NavBarCell2"><font size="-2">
&nbsp;PREV&nbsp;
&nbsp;NEXT</font></td>
<td bgcolor="white" class="NavBarCell2"><font size="-2">
  <a href="index.html" target="_top"><b>FRAMES</b></a>  &nbsp;
&nbsp;<a href="overview-summary.html" target="_top"><b>NO FRAMES</b></a>
&nbsp;&nbsp;
<script>
  <!--
  if(window==top) {
    document.writeln('<A HREF="allclasses-noframe.html" TARGET=""><B>All Classes</B></A>');
  }
  //-->
</script>
<noscript>
<a href="allclasses-noframe.html" target=""><b>All Classes</b></a>
</noscript>
</font></td>
</tr>
</table>
<!-- =========== END OF NAVBAR =========== -->

<hr>
<font size="-1">

</font>
<div class="jsdoc_ctime">Documentation generated by <a href="http://jsdoc.sourceforge.net/" target="_parent">JSDoc</a> on Thu May 21 12:19:24 2009</div>
</body>
</html>
